package ${packageName};

import android.arch.lifecycle.Observer;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;

import ${applicationPackage}.BR;
import ${applicationPackage}.R;
import ${applicationPackage}.databinding.${underscoreToCamelCase(layoutName)}Binding;
import ${packageName}.viewModel.${viewModelName};

import me.goldze.mvvmhabit.base.BaseActivity;

/** 
 * ${activityLable}
 */ 
public class ${activityClass} extends BaseActivity<${underscoreToCamelCase(layoutName)}Binding, ${viewModelName}> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.${layoutName};
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

//    @Override
//    public ${viewModelName} initViewModel() {
//        //View持有ViewModel的引用，如果没有特殊业务处理，这个方法可以不重写
//        return ViewModelProviders.of(this).get(${viewModelName}.class);
//    }
    @Override
    public void initViewObservable() {
		//监听ViewModel中pSwitchObservable的变化, 当ViewModel中执行【uc.pSwitchObservable.set(!uc.pSwitchObservable.get());】时会回调该方法
        viewModel.uc.pSwitchEvent.observe(this, new Observer<Boolean>() {
            @Override
            public void onChanged(@Nullable Boolean aBoolean) {
                //pSwitchObservable是boolean类型的观察者,所以可以直接使用它的值改变密码开关的图标
                if (viewModel.uc.pSwitchEvent.getValue()) {
                    //密码可见
                    //在xml中定义id后,使用binding可以直接拿到这个view的引用,不再需要findViewById去找控件了
                    binding.ivSwichPasswrod.setImageResource(R.mipmap.ic_login_show_psw_press);
                    binding.etPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                } else {
                    //密码不可见
                    binding.ivSwichPasswrod.setImageResource(R.mipmap.ic_login_show_psw);
                    binding.etPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
                }
            }
        });

    }
}
